﻿<views:MvxWpfView
    x:Class="Sidvall.WorkItemManager.UI.Wpf.Views.WorkItems.ConsoleWorkItemContextView"
    xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    xmlns:vms="clr-namespace:Sidvall.WorkItemManager.UI.ViewModels.WorkItems;assembly=Sidvall.WorkItemManager.UI"
    xmlns:Controls="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Controls" 
    xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:local="clr-namespace:Sidvall.WorkItemManager.UI.Wpf.Views.WorkItems"
    mc:Ignorable="d" 
    d:DesignHeight="400" d:DesignWidth="600">

    <views:MvxWpfView.Resources>
        <Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Converters:BooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" Not="True"/>
    </views:MvxWpfView.Resources>

    <Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:ConsoleWorkItemContextViewModel}}">
        <TabControl>
            <TabItem Header="Application Settings">
                <ScrollViewer VerticalScrollBarVisibility="Auto">
                    <StackPanel>
                        <StackPanel Margin="4">
                            <TextBlock Text="File Name" />
                            <TextBox Text="{Binding ContextItem.FileName}" IsEnabled="{Binding CanEdit}" />
                        </StackPanel>
                        <StackPanel Margin="4">
                            <TextBlock Text="Arguments" />
                            <TextBox Text="{Binding ContextItem.Arguments}" IsEnabled="{Binding CanEdit}" />
                        </StackPanel>
                        <StackPanel Margin="4">
                            <TextBlock Text="Working Directory" />
                            <TextBox Text="{Binding ContextItem.WorkingDirectory}" IsEnabled="{Binding CanEdit}" />
                        </StackPanel>
                        <StackPanel Margin="4">
                            <TextBlock Text="Sensor Provider" />
                            <TextBox Text="{Binding ContextItem.SensorProviderCodename}" IsEnabled="{Binding CanEdit}" />
                        </StackPanel>
                        <StackPanel Margin="4">
                            <CheckBox IsChecked="{Binding ContextItem.CreateNoWindow}" IsEnabled="{Binding CanEdit}">Create No Window</CheckBox>
                        </StackPanel>
                        <StackPanel Margin="4">
                            <CheckBox IsChecked="{Binding ContextItem.UseShellExecute}" IsEnabled="{Binding CanEdit}">Use Shell Execute</CheckBox>
                        </StackPanel>
                        <StackPanel Margin="4">
                            <CheckBox IsChecked="{Binding ContextItem.ErrorDialog}" IsEnabled="{Binding CanEdit}">Error Dialog</CheckBox>
                        </StackPanel>
                        <StackPanel Margin="4">
                            <TextBlock Text="Window Styles" />
                            <ComboBox ItemsSource="{Binding WindowStyles}" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding ContextItem.WindowStyle}"
                              Width="200" HorizontalAlignment="Left" />
                        </StackPanel>
                    </StackPanel>
                </ScrollViewer>
            </TabItem>
            <TabItem Header="Sensors">
                <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                    <Grid>
                        <Grid Visibility="{Binding ListIsVisible, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>

                            <Grid Grid.ColumnSpan="3" IsEnabled="{Binding CanEdit}">
                                <Grid.Background>
                                    <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                </Grid.Background>
                                <StackPanel Orientation="Horizontal">
                                    <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Add.png" 
                                        ToolTip="Add sensor" ButtonCommand="{Binding AddSensorCommand}" />
                                </StackPanel>
                            </Grid>

                            <DataGrid Grid.Row="1" RowHeaderWidth="0" ItemsSource="{Binding ContextItem.Sensors}" AutoGenerateColumns="False" CanUserAddRows="False" RowHeight="55" CanUserResizeColumns="False" CanUserReorderColumns="False" CanUserResizeRows="False" SelectedItem="{Binding ActiveSensor}">
                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="MouseDoubleClick">
                                        <i:InvokeCommandAction Command="{Binding EditSensorCommand}" CommandParameter="{Binding ActiveSensor}" />
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                                <DataGrid.Columns>
                                    <DataGridTemplateColumn Width="*" Header="Name">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Name}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="*" Header="Description">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="{Binding Description}" TextWrapping="Wrap" VerticalAlignment="Center" />
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                    Command="{Binding DataContext.EditSensorCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ConsoleWorkItemContextView}}}"
                                                    CommandParameter="{Binding}">
                                                    <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Edit.png" ToolTip="Edit sensor" />
                                                </Button>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                    <DataGridTemplateColumn Width="35" IsReadOnly="True">
                                        <DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
                                                    Command="{Binding DataContext.DeleteSensorCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ConsoleWorkItemContextView}}}"
                                                    CommandParameter="{Binding}"
                                                    Visibility="{Binding DataContext.CanEdit, Converter={StaticResource BooleanToVisibilityConverter}, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:ConsoleWorkItemContextView}}}">
                                                    <Image Source="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Delete.png" ToolTip="Delete sensor" />
                                                </Button>
                                            </DataTemplate>
                                        </DataGridTemplateColumn.CellTemplate>
                                    </DataGridTemplateColumn>
                                </DataGrid.Columns>
                            </DataGrid>
                        </Grid>
                        <Grid Visibility="{Binding ListIsVisible, Converter={StaticResource NotBooleanToVisibilityConverter}}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                                <RowDefinition />
                            </Grid.RowDefinitions>

                            <Grid Grid.ColumnSpan="3">
                                <Grid.Background>
                                    <SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
                                </Grid.Background>
                                <StackPanel Orientation="Horizontal">
                                    <Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.WorkItemManager.UI.Wpf;component/Images/Back.png" 
                                        ToolTip="Back to list" ButtonCommand="{Binding ShowSensorListCommand}" />
                                </StackPanel>
                            </Grid>
                            <StackPanel Grid.Row="1" IsEnabled="{Binding CanEdit}">
                                <StackPanel Margin="4">
                                    <TextBlock Text="Name" />
                                    <TextBox Text="{Binding ActiveSensor.Name}" IsEnabled="{Binding CanEdit}" />
                                </StackPanel>
                                <StackPanel Margin="4">
                                    <TextBlock Text="Description" />
                                    <TextBox Text="{Binding ActiveSensor.Description}" IsEnabled="{Binding CanEdit}" />
                                </StackPanel>
                            </StackPanel>
                        </Grid>
                    </Grid>
                </ScrollViewer>
            </TabItem>
        </TabControl>
    </Grid>
</views:MvxWpfView>
